export APP_ENV=test
#!/bin/bash

# 查找 gunicorn 主进程 PID
gunicorn_pid=$(ps aux | grep 'gunicorn' | grep -v 'grep' | grep 'bluesky' | awk '{print $2}')

log() {
  echo "$(date +"%Y-%m-%d %H:%M:%S") - $1"
  sleep 1
}

# 如果找到了主进程 PID
if [ -n "$gunicorn_pid" ]; then
  log "Found gunicorn process: $gunicorn_pid"
  kill -9 $gunicorn_pid
  sleep 2
else
  log "No running gunicorn process found"
fi

if [ $# -eq 1 ] && [ "$1" = "stop" ]; then
  log "[DONE]"
else
  log "Starting gunicorn process and child processes"
#  /usr/local/bin/python3.9 /usr/local/bin/gunicorn -w 1 -b 0.0.0.0:8000 -e APP_ENV=test app:app --name=bluesky
#  gunicorn main:app -c gunicorn.py --bind=0.0.0.0:7862 --name=bluesky
  gunicorn app:app -c gunicorn.py --bind=0.0.0.0:8000 --name=bluesky
  log "gunicorn process and child processes started"
fi

